package hzn.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/user")
public class UserCtrl {
    @Autowired
    StringRedisTemplate tmp;

    @RequestMapping("/setPhone")
    public void set(String phone){
        tmp.opsForValue().set("phone",phone);
    }

    @RequestMapping("/getPhone")
    public Map<String,Object> get(String name)throws Exception{
        String msg=tmp.opsForValue().get(name);
        Map m=new HashMap();
        m.put("phone",msg);
        return m;
    }

    @RequestMapping("/setMap")
    public Map<String,Object>setMap(String k,String v)throws Exception{
        if(tmp.hasKey("carts_abc")){
            System.out.println("abc的购物车存在");
        }
        tmp.opsForHash().put("carts_abc",k,v);
        System.out.println("存在"+k+"吗？"+tmp.opsForHash().hasKey("carts_abc",k));
        Map m=tmp.opsForHash().entries("carts_abc");
        return m;
    }

}
